package com.heng.controller;

import com.heng.dao.entity.address.CityEntity;
import com.heng.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/cities")
public class CityController {

    @Autowired
    private CityService cityService;

    // 新增城市
    @PostMapping
    public boolean addCity(@RequestBody CityEntity cityEntity) {
        return cityService.save(cityEntity);
    }

    // 删除城市（物理删除，无delFlag字段）
    @DeleteMapping("/{cityId}")
    public boolean deleteCity(@PathVariable Integer cityId) {
        return cityService.removeById(cityId);
    }

    // 更新城市
    @PutMapping
    public boolean updateCity(@RequestBody CityEntity cityEntity) {
        return cityService.updateById(cityEntity);
    }

    // 按ID查询城市
    @GetMapping("/{cityId}")
    public CityEntity getCityById(@PathVariable Integer cityId) {
        return cityService.getById(cityId);
    }

    // 按省份查询城市
    @GetMapping("/province/{province}")
    public List<CityEntity> getByProvince(@PathVariable String province) {
        return cityService.getByProvince(province);
    }

    // 查询所有城市
    @GetMapping("/all")
    public List<CityEntity> getAllCities() {
        return cityService.list();
    }
}